package com.crm.service.impl.sys.permissionManagement;

import com.crm.dao.mapper.customMapper.permissionManagement.SysMenuCustomMapper;
import com.crm.dao.mapper.sys.permissionManagement.SysCompanyMapper;
import com.crm.dao.mapper.sys.permissionManagement.SysMenuMapper;
import com.crm.model.entity.sys.permissionManagement.SysMenu;
import com.crm.model.entity.sys.permissionManagement.SysMenuExample;
import com.crm.service.sys.permissionManagement.SysMenuDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author yincuimei
 * @Date 2020/12/6 19:26
 */
@Service
public class SysMenuDbServiceImpl implements SysMenuDbService {

    @Resource
    private SysMenuMapper sysMenuMapper;

    @Autowired
    private SysMenuCustomMapper sysMenuCustomMapper;

    @Autowired
    SysMenuDbService sysMenuDbService;

    @Autowired
    SysCompanyMapper sysCompanyMapper;

    static List<String> menulist = new ArrayList<>();


    /**
     * 增加一条菜单记录
     * @param sysMenu ---菜单信息
     * @return
     */
    @Override
    public Boolean insertSysMenu(SysMenu sysMenu) {
        return sysMenuMapper.insert(sysMenu) > 0;
    }

    /**
     * 修改一条菜单记录
     * @param sysMenu ---菜单信息
     * @return
     */
    @Override
    public Boolean updateSysMenuById(SysMenu sysMenu) {
        return sysMenuMapper.updateByPrimaryKeySelective(sysMenu) > 0;
    }

    /**
     * 超级管理员查询所有左侧菜单列表(登录授权)
     * @param deleteStatus  ---删除状态(0:正常;1:已删除)
     * @param sysId         ---系统ID
     * @param menuType      ---菜单类型(1:管理; 2:用户)
     * @return
     */
    @Override
    public List<SysMenu> selectAllSysMenu(short deleteStatus, String sysId,String menuType) {
        return sysMenuCustomMapper.selectAllSysMenu(deleteStatus,sysId,menuType);
    }

    /**
     * 根据用户账号ID及系统ID查询菜单列表(登录授权)
     * @param deleteStatus  ---删除状态(0:正常;1:已删除)
     * @param accountId     ---账号ID
     * @param sysId         ---系统ID
     * @param menuType      ---菜单类型(1:管理; 2:用户)
     * @return
     */
    @Override
    public List<SysMenu> selectSysMenuByAccountId(short deleteStatus, String accountId, String sysId,String menuType) {
        return sysMenuCustomMapper.selectSysMenuByAccountId(deleteStatus,accountId,sysId,menuType);
    }

    /**
     * 根据账号ID及系统ID查询管理模块菜单条数
     * @param deleteStatus  ---删除状态(0:正常;1:已删除)
     * @param accountId     ---账号ID
     * @param sysId         ---系统ID
     * @param menuType      ---菜单类型(1:管理; 2:用户)
     * @return
     */
    public int selectManagerSyMenuCountByAccountId(short deleteStatus, String accountId, String sysId,String menuType){
        return sysMenuCustomMapper.selectManagerSyMenuCountByAccountId(deleteStatus,accountId,sysId,menuType);
    }




    /**
     * @Author wll
     * @param systemType 1 OA系统   2 CRM系统
     * @return
     */

    /**
     * @Author wll
     * @return
     */
    public List<SysMenu> getSystemTypeMenuData(Integer systemType){
        SysMenuExample sysMenuExample = new SysMenuExample();
        SysMenuExample.Criteria criteria = sysMenuExample.createCriteria();
        criteria.andSysIdEqualTo(String.valueOf(systemType)).andDeleteStatusEqualTo(Short.parseShort("0"));
        sysMenuExample.setOrderByClause("menu_level asc");
        sysMenuExample.setOrderByClause("menu_order asc");
        List<SysMenu> sysMenus =sysMenuMapper.selectByExample(sysMenuExample);
        return sysMenus;
    }

}
